import  * as PersonalCertificationAlipayService from 'services/PersonalCertificationAlipayService';

import {Toast} from 'antd-mobile';
export default {
  namespace: 'PersonalCertificationAlipayModel',
  state: {
    bizNo:''
  },
  effects: {
    *postAlipayVerification({ payload, callback }, { call, put }) {
      Toast.loading('提交中！',0)
      const response = yield call(PersonalCertificationAlipayService.postAlipayVerification, payload);
      let { code } = response
      let reg = new RegExp(/0000$/, 'i')
      if(reg.test(code)){
        Toast.hide()
        const {zhimaCertificateUrl,bizNo}=response
        yield put({
          type: 'setData',
          payload: {bizNo}
        });
        yield callback('success', zhimaCertificateUrl)
      }else {
        Toast.fail('提交失败')
        yield callback('error')
      }

    },
  },
  reducers: {
    setData(state, { payload }) {
      return {
        ...state,
       payload,
      }
    }
  }
};
